<script>
	import { mapActions } from "vuex";
	import { mapGetters } from "vuex";
	export default {
		onLaunch() {
			if (uni.getStorageSync("token")) {
			      // 如果已经登录，设置vuex登录状态
			      this.setUser(JSON.parse(uni.getStorageSync("token")));
			    }
			console.log('App Launch')
		},
		onLoad() {
		},
		onShow() {
			console.log("hh")
			this.$nextTick(function(){
				this.toserve();
				this.getCar()
			})
		
			console.log('App Show')
		},
		onHide() {
			console.log('App Hide')
		},
		 computed: {
			...mapGetters(["getUser", "getNum"])
		  },
		  watch: {
			 
		    // 获取vuex的登录状态

		  },
		    methods: {
		      ...mapActions(["setShoppingCart","setUser"]),
			  
			  toserve(){
				  
				  
				  this.$request
				  	.post("/users/login", {
				  		userName: this.$store.getters.getUser.userName,
				  		password: this.$store.getters.getUser.password
				  	})
				  	.then(res => {
						uni.showToast({
							title: "欢迎回来！",
							duration: 1000
						});
					})
					
			  },
			  getCar(){
				  this.$request
				    .post("/user/shoppingCart/getShoppingCart", {
				      user_id:this.$store.getters.getUser.user_id
				    }).then(res => {
				  	  console.log(res)
				      if (res.data.code === "001") {
				        // 001 为成功, 更新vuex购物车状态
				        this.setShoppingCart(res.data.shoppingCartData);
				      } else {
				        // 提示失败信息
				  	  uni.showToast({
				  		  title: res.data.msg,
				  		  duration: 1000
				  	  })
				      }
				    })
				    .catch(err => {
				      return Promise.reject(err);
				    });
			  }
			  

			  }
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	@import '@/common/common.css';
	@import '@/common/uni.css';
	@import '@/common/iconfont.css';
	/*每个页面公共css */
	::-webkit-scrollbar{
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}
</style>
